import React from "react";
import { useState, useEffect ,useRef} from "react";

export default function Add() {
  /**
   * react hooks
   * 1:useState
   * 参数1：state
   * 参数2：修改state的回调
   */
  const [count, setCount] = useState(0);
  const myRef=useRef();
  /**
   * 添加按钮事件
   */
  function add() {
    setCount((count) => count + 1);
  }

  function show(){
    const val=myRef.current.value;
    alert(val)
  }
  useEffect(() => {
    // didmount&&pdate
    return () => {
      // willUnmount
    };
  }, []);

  return (
    <div>
      {count}
      <input type="text" ref={myRef}/>
      <button onClick={add}>加1</button>
      <button onClick={show}>show</button>
    </div>
  );
}
